package com.shopping;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import com.shopping.dao.BaseDao;
import com.shopping.dao.UserDao;
import com.shopping.dao.impl.UserDaoImpl;
import com.shopping.pojo.User;

public class Test {
	public static void main(String[] args) throws SQLException {
//
//		Connection conn = null;
//		Statement stmt = null;
//		ResultSet rs = null;
//		ComboPooledDataSource spd = new ComboPooledDataSource("shopping");
//		try {
//			conn = spd.getConnection();
//			stmt = conn.createStatement();
//			String sql = "select * from users";
//			rs = stmt.executeQuery(sql);
//			while(rs.next()) {
//				System.out.println(rs.getString("username"));
//			}
//		}catch (Exception e) {
//			e.printStackTrace();
//		}
		
		BaseDao bd = new BaseDao();
		String sql = "select * from users";
		ArrayList<User> list;
		list = (ArrayList<User>) bd.query(sql, new BeanListHandler(User.class));
		for(int i=0; i<list.size(); i++) {
			System.out.println(list.get(i));
		}
		
	}
}
